@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

    <link rel="stylesheet" href="{{url('css/admin/jquery-ui.css')}}">
    <script type="text/javascript" src="{{url('css/admin/jquery-ui.min.js')}}"></script>
    <link href="{{url('js/lib/jquery-ui-timepicker-addon.css')}}" type="text/css" />
    <script src="{{url('js/lib/jquery-ui-timepicker-addon.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery.ui.datepicker-zh-CN.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery-ui-timepicker-zh-CN.js')}}" type="text/javascript"></script>
    <style>
        .sx{padding: 10px}
        .sx-btn{width: 64px;height: 30px;background-color: #4dbcd3;color: #fff;border: #4dbcd3;border-radius: 7%;}
        .sx-btn-excel{width: 128px;height: 30px;background-color: #4dbcd3;color: #fff;border: #4dbcd3;border-radius: 7%;}
    </style>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">订单管理</a>
            <em></em>
            <a href="#">售后列表</a>
        </div>
        <!-- cur-position end -->
        @include('admin.common.order-header')

        <div class="filter-box clearfix">
{{--            <div class="fl" style="display: inline-flex">--}}
{{--                <div class="sx">--}}
{{--                    <span>订单号：</span>--}}
{{--                    <input type="text" class="gg-ipt" style="width: 130px;height: 26px" placeholder="订单号" name="order_num" id="order_num" value="{{$orderNum}}">--}}
{{--                </div>--}}

{{--                <div class="sx">--}}
{{--                    <span>订单创建时间：</span>--}}
{{--                    <input class="gg-ipt" style="width: 130px;height: 26px" type="text" autocomplete="off" placeholder="开始时间" name="start_time" id="start_time" value="{{$startTime}}" />---}}
{{--                    <input class="gg-ipt" style="width: 130px;height: 26px" type="text" autocomplete="off" placeholder="结束时间" name="end_time" id="end_time" value="{{$endTime}}" />--}}
{{--                </div>--}}
{{--                <div class="sx">--}}
{{--                    <span>订单状态：</span>--}}
{{--                    <select name="status" id="status" value="">--}}
{{--                        <option value="0"  selected >全部</option>--}}
{{--                        <option value="1" @if($status && $status == 1) selected @endif>待付款</option>--}}
{{--                        <option value="2" @if($status && $status == 2) selected @endif>待发货</option>--}}
{{--                        <option value="3" @if($status && $status == 3) selected @endif>待收货</option>--}}
{{--                        <option value="4" @if($status && $status == 4) selected @endif>待评价</option>--}}
{{--                        <option value="5" @if($status && $status == 5) selected @endif>已完成</option>--}}
{{--                        <option value="6" @if($status && $status == 6) selected @endif>已取消</option>--}}
{{--                    </select>--}}
{{--                </div>--}}

{{--                <div class="sx">--}}
{{--                    <button class="sx-btn" id="sx_btn">筛选</button>--}}
{{--                </div>--}}
{{--                <div class="sx">--}}
{{--                    <button class="sx-btn-excel" id="sx_btn_excel">导出excel</button>--}}
{{--                </div>--}}
{{--            </div>--}}
{{--            <div class="sx">--}}
{{--                <button class="sx-btn" style="width: 100px;cursor: pointer" onclick="upPop()">退回地址设置</button>--}}
{{--            </div>--}}
        </div>


        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>头像</th>
                    <th>收货人</th>
                    <th>手机号</th>
                    <th>订单编号</th>
                    <th>是否支付</th>
{{--                    <th>支付方式</th>--}}
                    <th>订单状态</th>
                    <th>实付金额</th>
                    <th>售后类型</th>
{{--                    <th>退回单号</th>--}}
{{--                    <th>快递公司</th>--}}
                    <th>处理状态</th>
                    <th>客户描述</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($applies) > 0)
                    @foreach($applies as $a)
                        <tr id="admin_{{$a->id}}">
                            <td>{{$a->id}}</td>
                            <td><img src="{{$a->orders->photo_url}}" alt="" width="40px"></td>
                            <td>{{$a->orders->name}}</td>
                            <td>{{$a->orders->phone}}</td>
                            <td title="{{$a->orders->order_num}}">{{$a->orders->order_num}}</td>
                            <td>
                                @if($a->orders->is_pay == 0)
                                    <p style="color: red;">未支付</p>
                                @else
                                    <p style="color: #008200;">已支付</p>
                                @endif

                            </td>
                            <td>
                                @if($a->orders->status == 0)
                                    <p  style="color:red;">未完成</p>
                                @elseif($a->orders->status == 1)
                                    <p style="color:red;">待付款</p>
                                @elseif($a->orders->status == 2)
                                    <p style="color: red;">待发货</p>
                                @elseif($a->orders->status == 3)
                                    <p style="color:red;">待收货</p>
                                @elseif($a->orders->status == 4)
                                    <p style="color:red;">待评价</p>
                                @elseif($a->orders->status == 5)
                                    <p style="color:green;">完成</p>
                                @elseif($a->orders->status == 6)
                                    <p style="color:orange;">取消订单</p>
                                @elseif($a->orders->status == 7)
                                    <p style="color:red;">申请售后</p>
                                @elseif($a->orders->status == 8)
                                    <p style="color:red;">售后完成</p>
                                @endif

                            </td>
                            <td>{{$a->orders->s_amount}}</td>
                            <td>
                                @if($a->type==1)
                                    退款
                                    @elseif($a->type==2)
                                退货退款
                                    @else
                                换货
                                    @endif
                            </td>
{{--                            <td>{{$a->express_num}}</td>--}}
{{--                            <td>{{$a->express_company}}</td>--}}
                            <td>
                                @if($a->status==0)
                                    待处理
                                    @elseif($a->status==1)
                                已同意
                                    @elseif($a->status==2)
                                已拒绝
                                    @else
                                处理完成
                                    @endif

                            </td>
                            <td title="{{$a->desc}}">{{$a->desc}}</td>
                            <td>
                                @if($a->status==0)
                                    <a class="passOrderStatus" data-id="{{$a->id}}" href="javascript:;"><span style="color: green;">同意</span></a>
                                <span style="margin-right: 5px"></span>
                                    <a class="denyOrderStatus" data-id="{{$a->id}}" href="javascript:;"><span style="color: red;">拒绝</span></a>
                                @elseif($a->status==1)
                                    <a class="finishOrderStatus" data-id="{{$a->id}}" href="javascript:;"><span style="color: green;">完成</span></a>
                                @endif
                                <a class="color2" target="_blank" href="{{route('Admin.Home.ordersDetails')}}?id={{$a->orders->id}}">订单详情</a>


                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $applies->render(); ?>
        </div>
    </div>
    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <a class="close" href="javascript:void(0);"></a>
            <h3>退回地址设置</h3>
            <div class="fill-list">
                <span class="fill-tit">收件人：</span>
                <input class="gg-ipt" type="text" id="name" value="{{$address->name}}"/>
            </div>

            <div class="fill-list">
                <span class="fill-tit">手机号:</span>
                <input class="gg-ipt" type="text" id="phone" value="{{$address->phone}}"/>
            </div>

            <div class="fill-list">
                <span class="fill-tit">地址：</span>
                <input class="gg-ipt" type="text" id="address" value="{{$address->address}}" style="width:200px;"/>
            </div>

            <div class="fill-list">
                <span class="fill-tit">说明：</span>
                <input class="gg-ipt" type="text" id="remark" value="{{$address->remark}}" style="width:200px;"/>
            </div>

            <div class="fill-list">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" type="button" id="subThisForm" value="保存">
            </div>
        </div>
    </div>
    </div>
    <!-- content end -->
    <script>
        function upPop(){
            $('.upPop-box').upPop();

        }
        $(function(){

            $(document).on('click', '.passOrderStatus', function () {
                var id   = $(this).attr('data-id');

                $.ajax({
                    url: '{{route("Api.Admin.order.setOrderRefund")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id:id,
                        status:'pass'
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
            $(document).on('click', '.denyOrderStatus', function () {
                var id   = $(this).attr('data-id');

                $.ajax({
                    url: '{{route("Api.Admin.order.setOrderRefund")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id:id,
                        status:'deny'
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
            $(document).on('click', '.finishOrderStatus', function () {
                var id   = $(this).attr('data-id');

                $.ajax({
                    url: '{{route("Api.Admin.order.setOrderRefund")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id:id,
                        status:'finish'
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
            $(document).on('click', '#subThisForm', function () {
                var name  = $('#name').val();
                var phone = $('#phone').val();
                var address   = $('#address').val();
                var remark   = $('#remark').val();

                $.ajax({
                    url: '{{route("Api.Admin.sys.setReturnAddress")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        name:name,
                        phone:phone,
                        address:address,
                        remark:remark,

                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
        });
    </script>

@endsection